<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>

<script>
    var event = {
        list: [],
        listen: function(key, fn) {
            if (!this.list[key]) {
                this.list[key] = []
            }
            this.list[key].push(fn)
        },
        trigger: function() {
            var key = arguments[0]
            Array.prototype.shift.call(arguments)
            if (this.list[key]) {
                for (var i = 0; i < this.list[key].length; i++) {
                    this.list[key][i].apply(this, arguments)
                }
            }
        }
    }

    function event1(a, b) {
        console.log(a + b)
    }

    function event2(a, b, c) {
        console.log(a + b + c)
    }

    event.listen('event1', event1)
    event.listen('event2', event2)

    event.trigger('event1', 1, 2)
    event.trigger('event2', 1, 2, 3)
</script>